<script setup>
import HomePanel  from '@/views/Home/components/HomePanel.vue';

import { onMounted, ref } from "vue";
import { getCategoryProductListAPI } from '@/apis/homeAPI'

const categoryProductList = ref([]);
const getCategoryProductList = async () =>{
      //业务逻辑

      //调用接口
      const res = await getCategoryProductListAPI();
      categoryProductList.value = res.data;
}

onMounted(() => {
    getCategoryProductList();
});

</script>

<template>
  <div class="home-product">
    <HomePanel :title="cate.name" v-for="cate in categoryProductList" :key="cate">
    <template #main>
      <div class="box">
        <ul class="goods-list" >
            <!-- 大图，跨2列 -->
            <li class="cover">
              <RouterLink to="/">
                <img v-img-lazy="cate.pic" />
              </RouterLink>
            </li>
            <!-- 小图，正常渲染 -->
            <li v-for="i in cate.productInfoVOList" :key="i">
              <RouterLink :to="`/detail/${i.id}`" class="goods-item">
                <img v-img-lazy="i.pic" alt="" />
                <p class="name ellipsis">{{i.productName}}</p>
                <p class="desc ellipsis">{{i.description}}</p>
                <p class="price">&yen;{{i.price}}</p>
                <div class="extra">
                  <a aria-current="page" href="#/">
                    <p>猜你喜欢</p>
                    <p>发现更多宝贝</p>
                  </a>
                </div>
              </RouterLink>
            </li>
          </ul>
      </div>
    </template>
  </HomePanel>

  </div>
</template>

<style scoped lang='scss'>
.home-product {
  width: 1280px;
  margin: 0 auto;
  background: #fff;
  margin-top: 20px;

  .goods-list {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-auto-rows: 300px;
    gap: 10px;
    width: 100%;


    .cover {
      grid-column: span 2; // 跨2列
      border: #e7e7e7 1px solid;
      border-radius: 4px;
      overflow: hidden;
      a {
        display: block;
        width: 100%;
        height: 100%; // 关键：RouterLink 也要100%高
      }
      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        display: block;
        transition:
        transform 0.6s cubic-bezier(0.22, 1, 0.36, 1),
        box-shadow 0.6s cubic-bezier(0.22, 1, 0.36, 1),
        filter 0.6s cubic-bezier(0.22, 1, 0.36, 1);
        will-change: transform, box-shadow, filter;
        backface-visibility: hidden;
      }
      &:hover img {
        transform: scale(1.07);
        box-shadow: 0 24px 48px 0 rgba(0,0,0,0.18), 0 1.5px 6px 0 rgba(0,0,0,0.08);
        filter: brightness(1.10) contrast(1.08) saturate(1.04);
        z-index: 2;
      }
    }

    li {
      border: #e7e7e7 1px solid;
      border-radius: 4px;
      overflow: hidden;
      background: #fff;
      position: relative;
      // 让小图内容均匀分布
      .goods-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        height: 100%;
        padding: 16px 10px 10px 10px;
        box-sizing: border-box;
        text-align: center;
        transition: all .5s;
        border: 1px solid transparent;
        overflow: hidden;

        &:hover {
          border: 1px solid #27ba9b;
          border-radius: 4px;
        }

        img {
          width: 140px;
          height: 180px;
          object-fit: cover;
          margin: 0 auto;
          display: block;
          flex-shrink: 0;
        }

        .name,
        .desc,
        .price {
          width: 100%;
          text-align: center;
          margin: 0;
          padding: 0;
          line-height: 1.5;
        }

        .desc {
          color: #999;
          height: 20px;
        }

        .price {
          color: $priceColor;
          font-size: 16px;
        }

        .extra {
          position: absolute;
          left: 0;
          bottom: 0;
          height: 70px;
          width: 100%;
          background-color: #27ba9b;
          text-align: center;
          transform: translateY(100%);
          opacity: 0;
          transition: all .5s;
          p {
            color: #ffffff;
            font-size: 12px;
            line-height: 10px;
            &:first-child {
              font-weight: bold;
              position: relative;
              &::after {
                content: "";
                display: block;
                width: 60%;
                height: 1px;
                background: #fff;
                margin: 8px auto 10px auto;
                opacity: 0.7;
              }
            }
          }
        }

        &:hover .extra {
          transform: translateY(0);
          opacity: 1;
        }
      }
    }
  }
}
</style>
